import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_scan_tool/db/api_provider.dart';
import 'package:flutter_scan_tool/models/ToolLog.dart';

part 'tool_log_event.dart';
part 'tool_log_state.dart';

class ToolLogBloc extends Bloc<ToolLogEvent, ToolLogState> {
  ToolLogBloc() : super(ToolLogState()) {
    on<ToolLoadEvent>((event, emit) async {
      try {
        emit(ToolLogLoadingState());
        List<ToolLog> result = await ApiProvider.fetchToolLogList(event.toolId);
        emit(ToolLogLoadSuccessState(list: result));
      } catch (err) {
        emit(ToolLogLoadFailState());
      }
    });
  }
}
